package com.example.drug.jpa;

import java.util.Date;
import java.util.HashMap;
import java.util.Map;

import com.example.common.entity.Pharmacist;

import org.apache.ibatis.annotations.Update;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;

import feign.Param;
import org.springframework.transaction.annotation.Transactional;

public interface PharmacistRepository extends JpaRepository<Pharmacist, Long> {
    
    Pharmacist findByphone(String phone);

    Pharmacist findByOpenId(String openid);

    @Query(value = "select count(1) from order_rx_main where chk_dc_id_bigint = ?1 and chk_status_tinyint = ?2 and create_time_datetime > ?3 and create_time_datetime < ?4 and is_recipe_doc_ca_bit = 1",nativeQuery = true)
    Integer findCountTodayByDcId(Long chkid, Integer chkstatus, Date beg, Date end);

    @Query(value = "select count(1) from order_rx_main where chk_dc_id_bigint = ?1  and chk_time_datetime > ?2 and chk_time_datetime < ?3 and is_trial_pharm_ca_bit = 1",nativeQuery = true)
    Integer countTodayChecked(Long chkid,Date beg, Date end);

    @Query(value = "select ca_code_nvarchar from  doctor_pharmacist where phone_nvarchar = ?1", nativeQuery = true)
    String getCaMessage(String phone);

    @Modifying
    @Transactional
    @Query(value = "update order_rx_main set trial_pharm_signcertificate_nvarchar = ?1, trial_pharm_signature_value_nvarchar = ?2 where  rx_order_nO_nvarchar = ?3", nativeQuery = true)
    int updateSigJob(String signCert, String signResult, String orderId);

    /**
     * 药师端修改签名结果
     * @param orderId 订单id
     * @param timeSignature 时间戳签名
     * @return 修改行数
     */
    @Modifying
    @Transactional
    @Query(value = "update order_rx_main set is_trial_pharm_ca_bit = 1, chk_status_tinyint = 1, trial_pharm_time_stamp_nvarchar = ?2 where rx_order_nO_nvarchar = ?1", nativeQuery = true)
    int updateVerify(String orderId, String timeSignature);
}

